
/**
 * NO.01 添加卡控，输入数值超过标准上下限时 弹出错误提示.
 * NO.02 添加BY内部订单上报参数.
 */

$(document).ready(function() {
    $("form").submit(function(){
        return false;
    });
    var GlobalBean = {
        NORMAL : "0000000",
        mes_id : null,
        opeKey : null,
        T_FBPBISTOL : "FBPBISTOL",
        F8_KEY : 119
    };
    var VAL = {
        T_XPINQCOD : "XPINQCOD" ,
        NORMAL     : "0000000",
        EVT_USER   : $("#userId").text()
    };
    var domObj = {
        $window        : $(window),
        $prdSeqInfoDiv : $("#prdSeqInfoDiv"),
        $prdSeqInfoGrd : $("#prdSeqInfoGrd"),
        $grdDiv        : $("#grdDiv"),
        $itemDiv       : $("#itemDiv")
    };
    var prdItemInfoCM = [
        {name : 'prd_seq_id'    ,index : 'prd_seq_id'    ,label : PRD_SEQ_ID_TAG,width : PRD_SEQ_ID_CLM },
        {name : 'fab_sn'        ,index : 'fab_sn'        ,label : PRD_SEQ_ID_TAG,width : PRD_SEQ_ID_CLM,hidden:true},
        {name : 'box_id_fk'     ,index : 'box_id_fk'     ,label : BOX_TAG       ,width : BOX_ID_FK_CLM},
        {name : 'mdl_id_fk'     ,index : 'mdl_id_fk'     ,label : BOX_TAG       ,width : MDL_ID_FK_CLM     ,hidden : true},
        {name : 'cr_path_id_fk' ,index : 'cr_path_id_fk' ,label : BOX_TAG       ,width : CR_PATH_ID_FK_CLM ,hidden : true},
        {name : 'cr_path_ver_fk',index : 'cr_path_ver_fk',label : BOX_TAG       ,width : CR_PATH_VER_FK_CLM,hidden : true},
        {name : 'cr_ope_no_fk'  ,index : 'cr_ope_no_fk'  ,label : BOX_TAG       ,width : CR_OPE_NO_FK_CLM  ,hidden : true},
        {name : 'cr_ope_id_fk'  ,index : 'cr_ope_id_fk'  ,label : BOX_TAG       ,width : CR_OPE_ID_FK_CLM  ,hidden : true},
        {name : 'cr_ope_ver_fk' ,index : 'cr_ope_ver_fk' ,label : BOX_TAG       ,width : CR_OPE_VER_FK_CLM ,hidden : true},
        {name : 'cr_proc_id_fk' ,index : 'cr_proc_id_fk' ,label : BOX_TAG       ,width : CR_PROC_ID_FK_CLM ,hidden : true},
        {name : 'wo_id_fk'      ,index : 'wo_id_fk'      ,label : BOX_TAG       ,width : CR_PROC_ID_FK_CLM ,hidden : true},
        {name : 'lot_id'        ,index : 'lot_id'        ,label : BOX_TAG       ,width : CR_PROC_ID_FK_CLM ,hidden : true}
    ];
    $("#prdSeqInfoGrd").jqGrid({
        url : "",
        datatype : "local",
        mtype : "POST",
        height : 200,// TODO:需要根据页面自适应，要相对很高
        autowidth : true,// 宽度根据父元素自适应
        shrinkToFit : true,
        scroll : true,
        viewrecords : true,
        rownumbers : true,
        rowNum : 20,
        rownumWidth : 20,
        resizable : true,
        loadonce : true,
        toppager : true,
        fixed : true,
        pager : '#prdSeqInfoPg',
        pginput : true,
        fixed : true,
        cellsubmit : "clientArray",
        jsonReader : {
        },
        emptyrecords : true,// 当数据源为null时，显示为0
        colModel : prdItemInfoCM,
        onSelectRow : function(id) {
            f1QueryFnc();
        }
    });

    var toolFunc = {
    };
    var resetJqgrid = function() {

    };

    function getOpeListFnc() {
        var inTrxObj = {
            trx_id     : "FBPBISOPE" ,
            action_flg : 'L'
        };
        var  outTrxObj = comTrxSubSendPostJson(inTrxObj);
        if(outTrxObj.rtn_code == "0000000" ) {
            GlobalBean.opeKey = new Array();
            var oaryA = outTrxObj.oary;
            for(var i = 0; i < oaryA.length; i++){
                GlobalBean.opeKey.push({
                    ope_id : oaryA[i].ope_id,
                    ope_ver : oaryA[i].ope_ver
                });
                oaryA[i].dsc = oaryA[i].ope_id + ":" + oaryA[i].ope_dsc;
            }
            SelectDom.addSelectArr($("#opeIDSel"),outTrxObj.oary,["ope_id"],["ope_id"],"Y",true,false);
        }
    }

    function setMesIdSel(){
        var inObj,outObj,toolId;
        toolId = $("#toolIDSel").val();
        if(!toolId){
            return;
        }
        inObj = {
            trx_id:"FBPMITEML",
            action_flg : "Q",
            iary :[{
                tool_id_fk : toolId
            }]
        };
        outObj = comTrxSubSendPostJson(inObj);
        if(outObj.rtn_code === "0000000"){
            SelectDom.initWithSpace($("#mesIDSel"));
            SelectDom.addSelectArr($("#mesIDSel"),outObj.oary,["mes_id_fk"],["mes_id_fk"],"Y");

            SelectDom.initWithSpace($("#repUnit"));
            SelectDom.addSelectArr($("#repUnit"),outObj.oary,["rep_unit"],["rep_unit"],"Y");
        }

        //显示上报参数列表
        f1QueryFnc();
    }

    $("#toolIDSel").on("change",setMesIdSel);
    function itemRadioFnc() {
        var item = $("input[name='items']:checked").val();
        switch (item) {
            // case "lot" :
            //     $("#lotIDTxt").attr({'disabled' : false	});
            //     $("#boxIDTxt").attr({'disabled' : true  });
            //     $("#prdSeqIdTxt").attr({'disabled' : true });
            //     $("#woIDTxt").attr({'disabled' : true	});
            //     break;
            case "box" :
                $("#lotIDTxt").attr({'disabled' : true});
                $("#boxIDTxt").attr({'disabled' : false});
                $("#prdSeqIdTxt").attr({'disabled' : true});
                $("#woIDTxt").attr({'disabled' : true	});
                break;
            case "prdSeq" :
                $("#lotIDTxt").attr({'disabled' : true});
                $("#boxIDTxt").attr({'disabled' : true});
                $("#prdSeqIdTxt").attr({'disabled' : false});
                $("#woIDTxt").attr({'disabled' : true	});
                break;
            case "worder" :
                $("#woIDTxt").attr({'disabled' : false	});
                $("#lotIDTxt").attr({'disabled' : true});
                $("#boxIDTxt").attr({'disabled' : true});
                $("#prdSeqIdTxt").attr({'disabled' : true});
                break;
            default :
                $("#lotIDTxt").attr({'disabled' : true});
                $("#boxIDTxt").attr({'disabled' : true});
                $("#prdSeqIdTxt").attr({'disabled' : true});
                $("#woIDTxt").attr({'disabled' : true	});
                // alert("please choose one");
                break;
        }
    }

    $("input[name='items']").click(function() {
        itemRadioFnc();
    });

    $("#boxIDTxt").keypress(function(event) {
        if (event.keyCode == 13) {
            var inTrxObj = {
                trx_id : 'FIPINQBOX',
                action_flg : 'Q',
                box_id : $("#boxIDTxt").val()
            };
            var outTrxObj = comTrxSubSendPostJson(inTrxObj);
            if (outTrxObj.rtn_code == GlobalBean.NORMAL) {
                setGridInfo(outTrxObj.oary, "#prdSeqInfoGrd",true);
                SelectDom.setSelect($("#opeIDSel"),outTrxObj.cr_ope_id_fk,outTrxObj.cr_ope_id_fk);
                SelectDom.setSelect($("#toolIDSel"),outTrxObj.oary[0].cr_tool_id_fk,outTrxObj.oary[0].cr_tool_id_fk);
                setMesIdSel();
            }
        }
    });
    $("#prdSeqIdTxt").keyup(function(event) {
        var prdRowData, rowIDs, rowData;
        if (event.keyCode == 13) {
            query_main_prd_info_func();
        }
    });

    //查询是否存在重复玻璃ＩＤ
    function query_main_prd_info_func (){
        var prd_seq_id = $.trim($("#prdSeqIdTxt").val());
        if(prd_seq_id){
            inObj = {
                trx_id : "FIPINQSHT",
                action_flg : "F",
                fab_sn : prd_seq_id
            };
            outObj = comTrxSubSendPostJson(inObj);
            if (outObj.rtn_code == GlobalBean.NORMAL) {
                if(outObj.has_more_flg === "Y"){
                    FabSn.showSelectWorderDialog(prd_seq_id, outObj.oary3, function (data){
                        $("#prdSeqIdTxt").val(data.prd_seq_id);
                        query_prd_info_func();
                    });
                }else{
                    query_prd_info_func();
                }
            }
        }
    };

    function query_prd_info_func (){
        var prdRowData, rowIDs, rowData,prd_seq_id;
        $("#prdSeqInfoGrd").jqGrid("clearGridData");
        prd_seq_id = $.trim($("#prdSeqIdTxt").val());
        var inTrxObj = {
            trx_id : "FIPINQSHT",
            action_flg : "Q",
            prd_seq_id : prd_seq_id
        };
        var outTrxObj = comTrxSubSendPostJson(inTrxObj);
        if (outTrxObj.rtn_code == GlobalBean.NORMAL) {
            $("#prdSeqInfoGrd").jqGrid("addRowData",
                getGridNewRowID($("#prdSeqInfoGrd")), outTrxObj);
            $("#opeIDSel").val(outTrxObj.cr_ope_id_fk).trigger("change");
            $("#toolIDSel").val(outTrxObj.cr_tool_id_fk).trigger("change");
            $("#fromThicknessSpn").val(outTrxObj.from_thickness);
            $("#toThicknessSpn").val(outTrxObj.to_thickness);
            setMesIdSel();

        }
    }

	/*	$("#lotIDTxt").keypress(function(event) {
	 if (event.keyCode == 13) {
	 var lot_id,inTrx,outTrx;
	 lot_id = $(this).val();
	 inTrx = {
	 trx_id     : "XPINQLOT",
	 action_flg : "L",
	 lot_id     : lot_id
	 };
	 outTrx = comTrxSubSendPostJson(inTrx);
	 if(outTrx.rtn_code ==GlobalBean.NORMAL){
	 setGridInfo(outTrx.oary, "#prdSeqInfoGrd",true);

	 $("#toolIDSel").val(outTrx.oary[0].tool_id_fk).trigger("change");
	 $("#opeIDSel").val(outTrx.oary[0].nx_ope_id_fk).trigger("change");

	 setMesIdSel();
	 }
	 }
	 });*/
		$("#woIDTxt").keypress(function(event) {      //NO.02
	    if (event.keyCode == 13) {
	    var worder_id,inTrx,outTrx;
	     worder_id = $(this).val();
	     inTrx = {
	    trx_id     : "FIPINQWOR",
	    action_flg : "P",
	    worder_id  : worder_id
	    };
	     outTrx = comTrxSubSendPostJson(inTrx);
	     if(outTrx.rtn_code ==GlobalBean.NORMAL){
	    outTrx.oary5 = $.isArray(outTrx.oary5) ? outTrx.oary5 : [outTrx.oary5];
	    //无论是INPR,SHIP,WAIT都会显示出来？
	    setGridInfo(outTrx.oary5, "#prdSeqInfoGrd",true);
	    for (var i = 0; i < outTrx.oary5.length ; i++){
	        if(typeof (outTrx.oary5[i].cr_ope_id) != "undefined"){
                SelectDom.setSelect( $("#opeIDSel"),outTrx.oary5[i].cr_ope_id_fk,outTrx.oary5[i].cr_ope_id_fk);
                SelectDom.setSelect($("#toolIDSel"),outTrx.oary5[i].tool_id_fk,outTrx.oary5[i].tool_id_fk);
                break;
            }else{
	            continue;
            }
        }
	    setMesIdSel();
	    }
	 }
	 });
    function f1QueryFnc() {
           var  mesId = $("#mesIDSel").val();
           var repUnit = $("#repUnit").val();
            var iary1 = {
                tool_id_fk : $("#toolIDSel").find("option:selected").val(),
                // ope_no : rowData.cr_ope_no_fk,
                mes_id_fk : mesId,
                rep_unit : repUnit,// TODO
                data_pat : '00' // TODO
            };
            var inTrxObj1 = {
                trx_id : 'FBPMITEML',
                action_flg : 'I',
                iary : [iary1],
                // wo_id_fk : wo_id_fk
            };
            var outTrxObj1 = comTrxSubSendPostJson(inTrxObj1);
            if (outTrxObj1.rtn_code == GlobalBean.NORMAL) {
                var tbl_cnt = outTrxObj1.tbl_cnt;
                $("#dataItemEditDiv").empty();
                var str = '<table id="dataItemTbl" class="table table-striped table-bordered table-condensed" ><tr>'
                    + '<td class="Header_Text " >参数序号 </td>'
                    + '<td class="Header_Text " >参数名称 </td>'
                    + '<td class="Header_Text " >组内序号 </td>'
                    + '<td class="Header_Text " >参数说明 </td>'
                    + '<td class="Header_Text " >值 </td>'
                    + '<td class="Header_Text " >下限 </td>'
                    + '<td class="Header_Text " >上限</td></tr> ';
                for (var i = 0; i < tbl_cnt; i++) {
                        str = str + "<tr>" + '<td class=" dataItemTdCss">'
                            + outTrxObj1.oaryB[i].data_id + "</td>"
                            + '<td id ="tbl_data_group' + i
                            + '\" class=" dataItemTdCss">'
                            + outTrxObj1.oaryB[i].data_group + "</td>"
                            + '<td id ="tbl_data_group_seq' + i
                            + '\" class=" dataItemTdCss">'
                            + outTrxObj1.oaryB[i].data_group_seq + "</td>"
                            + '<td class=" dataItemTdCss">'
                            + outTrxObj1.oaryB[i].data_dsc + "</td>"
                            + '<td class=" dataItemTdCss">'
                            + '<input type="text" name=' + i + ' class ="span2 numberCssA" id="dataItem_'
                            + i + '_Txt\" />' + "</td>";
                        if (outTrxObj1.oaryB[i].l_spec) {
                            str = str + '<td class=" dataItemTdCss"' + 'id="lsl_' + i + '" >'
                                + outTrxObj1.oaryB[i].l_spec + "</td>";
                        }
                        if (outTrxObj1.oaryB[i].u_spec) {
                            str = str + '<td class=" dataItemTdCss"' + 'id="usl_' + i + '" >'
                                + outTrxObj1.oaryB[i].u_spec + "</td>";
                        }
                        +"</tr>";
                }
                str = str + "</table>";
                $(str).appendTo("#dataItemEditDiv");
                for (var i = 0; i < tbl_cnt; i++) {
                    $("#dataItem_" + i + "_Txt").focusout(function(event){
                       // if (event.keyCode == 13) {
                            dataItemKeyPressFnc(this);
                       // }
                    });

                }
//				GlobalBean.mes_id = oary.mes_id;
                showMessengerSuccessDialog("刷新列表成功!!",1);

                $(".numberCssA").blur(function() {
                    var $this = $(this);
                    var val = $this.val();
                    if (val && !isnumber(val)) {
                        showErrorDialog("", "[" + v7al + "]不是一个有效的数字,错误");
                        $this.val("");
                    }
                });

                function isnumber(str){
                    // return isInt(str) || isDouble(str) ;
                    return /(^(\-?)\d+$)|(^\d+\.\d+$)/.test(str);
                }

            }
        }


    /**
     * 当没有上下限时，usl，lsl的值是 Nan
     * value>usl,value<lsl 都不会成立
     * 可达到不参加check的目的
     */
    function dataItemKeyPressFnc(obj){
        var nextSelecter,uslSelector,lslSelector,usl,lsl,index,value;
        index = obj.id.split("_")[1];
        uslSelector = "#usl_"+index ;
        usl = parseFloat($(uslSelector).text());
        lslSelector = "#lsl_"+index;
        lsl = parseFloat($(lslSelector).text());
        value = parseFloat($(obj).val());
        if(value>usl){
            showMessengerErrorDialog("输入数值高于标准上限"+usl,2);
            $(obj).focus();
            return false;
        }else if(value<lsl){
            showMessengerErrorDialog("输入数值低于标准下限"+lsl,2);
            $(obj).focus();
            return false;
        }
        if(value){//防止不输入值默认选择下行
            nextSelecter = "#dataItem_" +( parseInt(obj.name,10)+1 ) + "_Txt";
            /* $(nextSelecter).focus();*/
        }
    }
    $("#f1_btn").click(f1QueryFnc);

    function f8ReportFnc(){
        var pecvd_flg = $("#f8_btn").data("pecvd_flg");
        if(pecvd_flg == "A"){
            //pecvd粘贴数据一次发送5片的数据
            pecvdReport();

        }else{
            var judgeStr = "OK";
            var tableItemCnt = 0;
            tableItemCnt = $("#dataItemTbl tr").length - 1;
            var iaryAry = new Array();
            for (var i = 0; i < tableItemCnt; i++) {
                if ($("#dataItem_" + i + "_Txt").val() != "") {
                    var iary = {
                        data_group : $("#tbl_data_group" + i).text(),
                        data_value : $("#dataItem_" + i + "_Txt").val(),
                        data_group_seq : $("#tbl_data_group_seq" + i).text(),
                        data_type : "03"
                    };

                    iaryAry.push(iary);
                    if (judgeStr != "NG"){
                        if(($("#dataItem_" + i + "_Txt").val()) < ($("#lsl_"+i ).text()) || ($("#dataItem_" + i + "_Txt").val()) > ($("#usl_"+i ).text())){
                            judgeStr = "NG";
                        }else {
                            judgeStr = "OK";
                        }
                    }
                }
            }

            var opeIdSel = $("#opeIDSel").find("option:selected").text();
            if(!opeIdSel){
                showErrorDialog("","必须选择站点");
                return false;
            }

            var shiftId = $("#shiftIDSel").find("option:selected").val();
            if(!shiftId){
                showErrorDialog("","必须选择班别");
                return false;
            }

            if(iaryAry.length == 0){
                showErrorDialog("","请输入上报数据！");
                return false;
            }

            // Send Tx
            var inTrxObj = {
                trx_id      :  'FQPEDCDAT',
                rep_unit_fk :  "M",
                // prd_seq_id  :  prd_seq_id,
                tool_id     :  $("#toolIDSel").find("option:selected").val(),
                data_pat_fk :  '00',
                mes_id_fk   :  $("#mesIDSel").find("option:selected").val(),
                lot_id:  $("#lot_id_fk").val(),
                // path_id     :  prdSeqRowData.cr_path_id_fk,
                // path_ver    :  prdSeqRowData.cr_path_ver_fk,
                // ope_no      :  prdSeqRowData.cr_ope_no_fk,
                ope_id      :  $("#opeIDSel").find("option:selected").val(),
                // ope_ver     :  prdSeqRowData.cr_ope_ver_fk,
                // proc_id     :  prdSeqRowData.cr_proc_id_fk,
                rpt_usr     :  $("#userId").text(),
                shift_id : $("#shiftIDSel").find("option:selected").val(),
                boat_number : $("#boatNumber").find("option:selected").val(),
                judgeStr    :  judgeStr,
                data_cnt    :  iaryAry.length,
                iary        :  iaryAry
            };

            //判断iary是否至少有一个值
            if(iaryAry.length == 0){
                showErrorDialog("","请输入要需要上报的数据!");
                return false;
            }

            spcThicknessRule.reportSPC(inTrxObj, GlobalBean.mes_id, "", "", "", function(outTrxObj){
                if (outTrxObj.rtn_code == VAL.NORMAL) {
                    showMessengerSuccessDialog("数据上报成功!!");
                    $("[id^='dataItem_']").val("");
                }

            });
        }
    }

    function pecvdReport(){
        var tableItemCnt = 0;
        tableItemCnt = $("#dataItemTbl tr").length - 1;

        var iaryList = new Array();
        for(var i = 0 ; i < 5; i++){
            var iaryAry = new Array();
            var mhseq = 0;
            var tglseq =0;
            //5个膜厚
            for(var m = 5*i; m < 5 + 5*i ;m++){
                var iary = {
                    data_group : $("#tbl_data_group" + m ).text(),
                    data_value : $("#dataItem_" + m + "_Txt").val(),
                    data_group_seq : $("#tbl_data_group_seq" + mhseq ).text(),
                    data_type : "03"
                };
                mhseq++;
                iaryAry.push(iary);
            }

            //5个透过率
            for(var n = 25 + 5*i ; n < 30 + 5*i ;n++){
                var iary ={
                    data_group : $("#tbl_data_group" + n ).text(),
                    data_value : $("#dataItem_" + n + "_Txt").val(),
                    data_group_seq : $("#tbl_data_group_seq" + tglseq ).text(),
                    data_type : "03"
                };
                tglseq++;
                iaryAry.push(iary);
            }

            iaryList.push(iaryAry);
        }


        var opeIdSel = $("#opeIDSel").find("option:selected").text();
        if(!opeIdSel){
            showErrorDialog("","必须选择站点");
            return false;
        }

        var shiftId = $("#shiftIDSel").find("option:selected").val();
        if(!shiftId){
            showErrorDialog("","必须选择班别");
            return false;
        }

        if(iaryAry.length == 0){
            showErrorDialog("","请输入上报数据！");
            return false;
        }


        for(var i = 0; i < iaryList.length; i++){
            // Send Tx
            var inTrxObj = {
                trx_id      :  'FQPEDCDAT',
                rep_unit_fk :  "M",
                tool_id     :  $("#toolIDSel").find("option:selected").val(),
                data_pat_fk :  '00',
                mes_id_fk   :  $("#mesIDSel").find("option:selected").val(),
                ope_id      :  $("#opeIDSel").find("option:selected").val(),
                rpt_usr     :  $("#userId").text(),
                shift_id : $("#shiftIDSel").find("option:selected").val(),
                boat_number : $("#boatNumber").find("option:selected").val(),
                // judgeStr    :  judgeStr,
                data_cnt    :  iaryList[i].length,
                iary        :  iaryList[i]
            };

            //判断iary是否至少有一个值
            // if(iaryList[i].length == 0){
            //     showErrorDialog("","请输入要需要上报的数据!");
            //     return false;
            // }

            spcThicknessRule.reportSPC(inTrxObj, GlobalBean.mes_id, "", "", "", function(outTrxObj){
                if (outTrxObj.rtn_code == VAL.NORMAL) {
                    showMessengerSuccessDialog("数据上报成功!!");
                    $("[id^='dataItem_']").val("");
                }
            });
        }

    };

    $("#f8_btn").click(f8ReportFnc);

    $("#report_tool").click(reportTool);

    function reportTool(){
        var tableItemCnt = 0;
        tableItemCnt = $("#dataItemTbl tr").length - 1;
        var iaryAry = new Array();
        for (var i = 0; i < tableItemCnt; i++) {
            if ($("#dataItem_" + i + "_Txt").val() != "") {
                var iary = {
                    data_group: $("#tbl_data_group" + i).text(),
                    data_value: $("#dataItem_" + i + "_Txt").val(),
                    data_group_seq: $("#tbl_data_group_seq" + i).text()
                };
                iaryAry.push(iary);
            }
        }

        var inTrxObj = {
           // rep_unit_fk :  "P",
            tool_id     :  $("#toolIDSel").find("option:selected").text(),
            //data_pat_fk :  '00',
            iary        :  iaryAry
        };
        var inTrxStr = JSON.stringify(inTrxObj);
        var outTrxObj;
        jQuery.ajax({
            type:"post",
            url: "reportTool.do",
            timeout:60000, // TODO 1min
            data:{
                strInMsg:inTrxStr
            },
            async:false, // false代表等待ajax执行完毕后才执行alert("ajax执行完毕")语句;
            success: function(data){
                outTrxObj =  JSON.parse(data);
                var rtn_code = outTrxObj.rtn_code;
                if (rtn_code != "0000000") {
                    if(showErrDlg &&
                        showErrDlg == "N" ){
                        ;
                    }else{
                        showErrorDialog(rtn_code,outTrxObj.rtn_mesg);
                    }
                }
            },
            error : function(xhr, stat, e){
                console.error(xhr);

            }
        });

        if (outTrxObj.rtn_code == VAL.NORMAL) {
            showSuccessDialog("上报成成功！");
        }
    }


    function setToolListFnc(){
        // $("#toolIDSel").empty();
        var fabId =  $.trim($("#fabIdSel").val());
        var lineId =   $.trim($("#lineIdSel").val());
        var opeId = $.trim($("#opeIDSel").val());
        var opeVer = '00000';
        var iary2  = {
            fab_id_fk : fabId,
            bay_id :lineId,
            ope_id_fk : opeId,
            ope_ver : opeVer
        }
        var inObj2 = {
            trx_id : 'FBPBISTOL',
            action_flg : "Q",
            iary : [iary2]
        };
        var outObj2 = comTrxSubSendPostJson(inObj2);
        if(outObj2.rtn_code === "0000000"){
            SelectDom.addSelectArr($("#toolIDSel"),outObj2.oary,["tool_id"],["tool_dsc"],"Y",true,false);
        }
    };

    //pecvd设备组加载舟号
    function initBoatNumber(){
        SelectDom.initWithSpace($("#boatNumber"));
        var toolId = $("#toolIDSel").val();
        var iary  = {
            tool_id : toolId,

        }
        var inObj2 = {
            trx_id : 'FBPBISTOL',
            action_flg : "I",
            iary : [iary]
        };
        var outObj2 = comTrxSubSendPostJson(inObj2);
        if(outObj2.rtn_code === "0000000"){
            //设备组代码
           if(outObj2.oary[0].tool_group_id_fk === "$TPECVD"){
               initZhListFnc();
           }
        }
    };



    $("#clear_btn").click(function() {
        $("[id^='dataItem_']").val("");
    });

    document.onkeydown = function(event) {
        if(event.keyCode == F8_KEY){
            f8ReportFnc();
        }
        return true;
    };

    // 2.初始化上报类别
     function initRepUnit() {
        //SelectDom.initWithSpace(domObj.$repUnit);
        addValueByDataCateFnc("#repUnit", "MLRU", "data_ext");
    };

     //初始化厂别
    function setFabListFnc(){
        comAddValueByDataCateFnc("#fabIdSel","FBID","data_ext","data_desc",true,false);
    };

    //初始化线别
    function setLineListFnc(){
        comAddValueByDataCateFnc("#lineIdSel","AREA","data_ext","data_desc",true,false);
    };

    //初始化班别
    function initShiftFnc(){
        comAddValueByDataCateFnc("#shiftIDSel","SHIF","data_id","data_desc",true,false);
    }

    //初始化舟号
    function initZhListFnc(){
        comAddValueByDataCateFnc("#boatNumber","ZH","data_id","data_desc",true,false);
    };

    //初始化道
    function initDaoListFnc(){
        comAddValueByDataCateFnc("#road","DAO","data_id","data_desc",true,false);
    };

    function initFnc() {
        $("#itemDiv").css({
            height : ($(document).height() * 0.7)
        });
        resetJqgrid();
        itemRadioFnc();
        getOpeListFnc();
        initRepUnit();
        setFabListFnc();
        setLineListFnc();
        setToolListFnc();
        initShiftFnc();
        //getToolListFnc();
        $("#fromThicknessSpn").val("");
        $("#toThicknessSpn").val("");

    }
    initFnc();

    $("#fabIdSel").on("change",setToolListFnc);
    $("#lineIdSel").on("change",setToolListFnc);
    $("#opeIDSel").on("change",setToolListFnc);
    $("#toolIDSel").on("change",initBoatNumber);

    //绑定在了body上，也可以绑定在其他可用元素行，但是不是所有元素都支持copy和past事件。
    $('#pevcd_data').bind({
        // copy: function(e) {//copy事件
        //     var cpTxt = "复制的数据";
        //     var clipboardData = window.clipboardData; //for IE
        //     if (!clipboardData) { // for chrome
        //         clipboardData = e.originalEvent.clipboardData;
        //     }
        //     //e.clipboardData.getData('text');//可以获取用户选中复制的数据
        //     clipboardData.setData('Text', cpTxt);
        //     alert(cpTxt);
        //     $('#pevcd_data').text('Copy Data : ' + cpTxt);
        //     return false;//否则设不生效
        // },
            paste: function(e) {//paste事件
            var eve = e.originalEvent
            var cp = eve.clipboardData;
            var data = null;
            var clipboardData = window.clipboardData; // IE
            if (!clipboardData) { //chrome
                clipboardData = e.originalEvent.clipboardData
            }
            data = clipboardData.getData('Text');
            var tableItemCnt = 0;
            tableItemCnt = $("#dataItemTbl tr").length - 1;
            if(tableItemCnt <=  0){
                showErrorDialog("","是请先加载参数列表！！");
                return false;
            }

            var dataArr = data.split("\n");
            var reg = RegExp(/Thickness:   /);
            var reg2 = RegExp(/n:           /);
            var mhList = [];//膜厚数组
            var tglList = [];//透过率数组
            for(var i = 0; i < dataArr.length; i++){
                if(dataArr[i].match(reg)){
                   var mh = dataArr[i].split("Thickness:   ")[1];
                   mhList.push(mh);
                   continue;
                }
                if(dataArr[i].match(reg2)){
                    var tgl = dataArr[i].split("n:           ")[1];
                    tglList.push(tgl);
                    continue;
                }
            }

                for(var i = 0; i < mhList.length;i++){
                        var mh = mhList[i].split("nm")[0].replace(/(^\s*)|(\s*$)/g, "");
                    $("#dataItem_" + i + "_Txt").val(mh);
                }

                for(var i = 0 ; i <  tglList.length ;i++){
                    var tgl = tglList[i].replace(/(^\s*)|(\s*$)/g, "");
                    $("#dataItem_" + (i+mhList.length) + "_Txt").val(tgl);
                }

                // var iaryAry = new Array();
                // for (var i = 0; i < tableItemCnt; i++) {
                //     if ($("#dataItem_" + i + "_Txt").val() != "") {
                //         var iary = {
                //             data_group : $("#tbl_data_group" + i).text(),
                //             data_value : $("#dataItem_" + i + "_Txt").val(),
                //             data_group_seq : $("#tbl_data_group_seq" + i).text()
                //         };
                //         iaryAry.push(iary);
                //     }
                // }
                $("#f8_btn").data("pecvd_flg","A");

            $('#pevcd_data').html(data);
        }
    });


    $(window).resize(function() {
        resetJqgrid();
    });
    function resizeFnc(){
        var offsetBottom, divWidth;

        divWidth = domObj.$prdSeqInfoDiv.width();
        // offsetBottom = domObj.$window.height() - domObj.$prdSeqInfoDiv.offset().top;
        domObj.$grdDiv.height(domObj.$window.height() - domObj.$grdDiv.offset().top);
        domObj.$itemDiv.height(domObj.$window.height() - domObj.$itemDiv.offset().top);
        // domObj.$prdSeqInfoDiv.height(offsetBottom * 0.80);
        domObj.$prdSeqInfoGrd.setGridWidth(divWidth * 0.99);
        // domObj.$prdSeqInfoGrd.setGridHeight(offsetBottom * 0.80 - 80);
    };
    resizeFnc();
    domObj.$window.resize(function() {
        resizeFnc();
    });

});
